#ifndef DWM_CLIENT_H
#define DWM_CLIENT_H

#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <string>

#include "logging.h"

#define COMMAND_LENGTH 1


class client : LoggingService
{
  public:
    explicit client(const std::string &server_addr);
    ~client();
    client(const client &c);

    void login(const std::string &username, const std::string &password);

    void connect();

    void disconnect();

    void operator ()();

    void thread_process();


  private:

    void login();

    void handle_resolve_to(const boost::system::error_code &err, boost::asio::ip::tcp::resolver::iterator iterator);

    void handle_resolve_from(const boost::system::error_code &err, boost::asio::ip::tcp::resolver::iterator iterator);

    void handle_connect_to(const boost::system::error_code &err, boost::asio::ip::tcp::resolver::iterator iterator);

    void handle_connect_from(const boost::system::error_code &err, boost::asio::ip::tcp::resolver::iterator iterator);

    void handle_read_command_from(const boost::system::error_code& err);

    void listen_from();

    boost::thread * m_client_thread;

    boost::asio::io_service m_io_service;

    boost::asio::ip::tcp::resolver m_resolver;

    boost::asio::ip::tcp::socket m_socket_to;
    boost::asio::ip::tcp::socket m_socket_from;

    std::string m_server; 

    bool m_is_connected_to;
    bool m_is_connected_from;
    bool m_is_connected;

    bool m_is_authenticated;

    bool m_is_bidirectional;

    std::string m_username;
    std::string m_password;

    char m_buffer[1024];




};


#endif
